package com.zy.Conterller;

import com.zy.pojo.Mx;
import com.zy.service.MxService;
import com.zy.vo.ManagementVo;
import com.zy.vo.ResultVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/mx/count")
public class Mxcount {
    @Resource
    private MxService mxService;
    @GetMapping("list")
    public ResultVo getMxList(){
        return ResultVo.success(mxService.getmxList());
    }
    @GetMapping("mxlist/{pageSize}/{pageNo}")
    @RequiresPermissions("mxchaser:list")
    public ResultVo getPurList(@PathVariable Integer pageSize, @PathVariable Integer pageNo, ManagementVo managementVo){
        try{
            return ResultVo.success(mxService.getPage(pageNo,pageSize,managementVo));
        }catch (Exception e) {
            return ResultVo.fail("查询失败");
        }
    }
    @PostMapping("add")
    @RequiresPermissions("mxchaser:add")
    public ResultVo getRoleadd(@RequestBody Mx mx){
        try{
            mxService.add(mx);
            return ResultVo.success("明细添加成功");
        }catch (Exception e){
            return ResultVo.fail("明细添加失败",e);
        }
    }
     @GetMapping("err/{id}")
     @RequiresPermissions("mxchaser:err")
    public ResultVo getMxSelect(@PathVariable String id){
        try{
            mxService.select(Integer.parseInt(id));
            return ResultVo.success("查看采购明细成功");
        }catch (Exception e){
            return ResultVo.fail("查看采购明细失败");
        }
    }
    @GetMapping("del/{id}")
    @RequiresPermissions("mxchaser:del")
    public ResultVo del(@PathVariable String id){
        try{
            mxService.del(Integer.parseInt(id));
            return ResultVo.success("采购合同删除成功");
        }catch (Exception e){
            return ResultVo.fail("采购合同删除失败");
        }
    }
    @PostMapping("go")
    @RequiresPermissions("mxchaser:go")
    public ResultVo getMxHoused(@RequestBody Mx mx){
        try{
            mxService.getMxHoused(mx);
            return ResultVo.success("商品添加到入库单");
        }catch (Exception e){
            return  ResultVo.fail("商品添加入库失败");
        }
    }
}
